#include "Fun_Message_Fifo.h"
#include "string.h"
#include "queue_pxprog.h"

static queue_t  stEventFifo;
enum ENFUNSTATELIST sEventFifobuf[_FunMessLen_];

 
void
FunMessage_Init (enum ENFUNSTATELIST *enMeterEventBuf, unsigned short ilen)
{ 
queue_create(&stEventFifo,sEventFifobuf, ilen, sizeof(enum ENFUNSTATELIST));
}

static enum ENMFUNMESSAGERESULT
FunMessage_Push_Io (enum ENFUNSTATELIST enEvent)
{
	bool enbool =
   queue_put(&stEventFifo,  &enEvent);
	
	return (true == enbool)?_enFunMESS_SUCCESS_:_enFunMESS_ERROR_;
}

static enum ENMFUNMESSAGERESULT
FunMessage_TopPush_Io (enum ENFUNSTATELIST enEvent)
{
	bool queue_topput(queue_t *q,  void *element);
	bool enbool =
   queue_topput(&stEventFifo, &enEvent);
	
	return (true == enbool)?_enFunMESS_SUCCESS_:_enFunMESS_ERROR_;
}

static enum ENMFUNMESSAGERESULT
FunMessage_Pop_Io (enum ENFUNSTATELIST *enEvent)
{	
	bool enbool =queue_get(&stEventFifo, enEvent);
 return (true == enbool)?_enFunMESS_SUCCESS_:_enFunMESS_ERROR_;
}
 
static void
FunMessage_Irq_Con (char en)
{
#ifdef _Fun_Dis_Irq_
  if (en)
    {
      _Fun_Mess_Irq_Enable ();
    }
  else
    {
      _Fun_Mess_Irq_Disable ();
    }
#endif
}


enum ENMFUNMESSAGERESULT
FunMessage_TopPush (enum ENFUNSTATELIST enEvent)
{
	
  enum ENMFUNMESSAGERESULT enResult;
  FunMessage_Irq_Con (0);	
  enResult = FunMessage_TopPush_Io (enEvent);
  FunMessage_Irq_Con (1);
  return enResult;
}


enum ENMFUNMESSAGERESULT
FunMessage_Push (enum ENFUNSTATELIST enEvent)
{
  enum ENMFUNMESSAGERESULT enResult;
  FunMessage_Irq_Con (0);
  enResult = FunMessage_Push_Io (enEvent);
  FunMessage_Irq_Con (1);
  return enResult;
}

enum ENMFUNMESSAGERESULT
FunMessage_Pop (enum ENFUNSTATELIST *enEvent)
{
  enum ENMFUNMESSAGERESULT enResult;
  FunMessage_Irq_Con (0);
  enResult = FunMessage_Pop_Io (enEvent);
  FunMessage_Irq_Con (1);
  return enResult;
}
